package cn.devzyh.oms.wsms.controller;

import cn.devzyh.oms.common.core.util.R;
import cn.devzyh.oms.common.excel.annotation.ResponseExcel;
import cn.devzyh.oms.common.log.annotation.SysLog;
import cn.devzyh.oms.common.mybatis.domain.PageQuery;
import cn.devzyh.oms.wsms.api.dto.StockLogDTO;
import cn.devzyh.oms.wsms.api.entity.StockLog;
import cn.devzyh.oms.wsms.api.vo.StockLogVO;
import cn.devzyh.oms.wsms.service.StockLogService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 库存日志
 *
 * @author devzyh
 * @date 2023-10-29
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/stock/log")
public class StockLogController {

	private final StockLogService stockLogService;

	/**
	 * 分页查询
	 *
	 * @param page     分页对象
	 * @param stockLog 查询条件
	 * @return R
	 */
	@GetMapping("/page")
	@PreAuthorize("@pms.hasPermission('wsms_stock_log_view')")
	public R getStockLogPage(@ModelAttribute PageQuery<StockLog> page, @ModelAttribute StockLogDTO stockLog) {
		return R.ok(stockLogService.list(page.mybatisPlusPage(), stockLog));
	}

	/**
	 * 通过ID查询
	 *
	 * @param id id
	 * @return R
	 */
	@GetMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('wsms_stock_log_view')")
	public R getById(@PathVariable("id") Long id) {
		return R.ok(stockLogService.getById(id));
	}

	/**
	 * 通过ID删除
	 *
	 * @return R
	 */
	@SysLog("删除库存日志")
	@DeleteMapping
	@PreAuthorize("@pms.hasPermission('wsms_stock_log_del')")
	public R remove() {
		return R.ok();
	}

	/**
	 * 导出Excel表格
	 *
	 * @param stockLog 查询条件
	 * @return excel 文件流
	 */
	@ResponseExcel
	@GetMapping("/export")
	@PreAuthorize("@pms.hasPermission('wsms_stock_log_export')")
	public List<StockLogVO> export(@ModelAttribute StockLogDTO stockLog) {
		return stockLogService.list(null, stockLog);
	}

}